<?php
	global $facebook,$session,$uid,$logoutUrl,$loginUrl,$me,$DEV_SENT_BY,$DEV_SENT_ON,$DEV_TAG_TITLE,$res;
	
	if (defined('USE_FACEBOOK')) {
		echo '<div id="fb-root"></div>';
		echo '<script>window.fbAsyncInit = function() {FB.init({appId : \''.$facebook->getAppId().'\',session : \''.json_encode($session).'\',status : true,cookie : true,xfbml : true // parse XFBML
	});FB.Event.subscribe(\'auth.login\', function() {window.location.reload();});};';
		echo '(function() {var e = document.createElement(\'script\');e.src = document.location.protocol + \'//connect.facebook.net/en_US/all.js\';e.async = true;document.getElementById(\'fb-root\').appendChild(e);
	}());</script>';
	}
	if ($res[2]!="detail") {
		(is_numeric($res[1])) ? $page = strip_tags($res[1]) : $page = 1;
		($_GET['showview']) ? $showview = strip_tags($_GET['showview']) : $showview = '';
		$numrec = NUMREC;
		$perpage = PAGE;	//jumlah record yang ditampilkan perhalaman
		if ($params['maxpage'])
			$perpage = $params['maxpage'];
		$defshow = DEFSHOW;
		if ($page!=0)
			$piro=($page-1)*$perpage;
		else
			$piro = 0;
		$g = 1;
		$c = 0;
		$lasttipe = array();

		echo '<div>';
		$sqlEvent = "SELECT * FROM tbl_content WHERE ".$tipe." AND status='1' ORDER BY tanggal DESC";
		if ($params['query']!="")
			$sqlEvent = $params['query'];
			
		$qryEvent = mysql_query($sqlEvent);
		$numEvent = mysql_num_rows($qryEvent);
		
		if ($numEvent==0) {
			echo '<div align="center">'.$DEV_NO_DATA.'</div>';
		} else {
			$numEvent = array();
			while ($rowEvent = mysql_fetch_object($qryEvent)) {
				$numEvent[$numrec] = $rowEvent->idx;
				$numrec++;
			}
			$divpage = $queryData->showpage('index.php',$numrec,$defshow,$perpage,$page,$showview);
			$rowEvent = "";
			for ($i=$piro;$i<($piro+$perpage);$i++) {
				$rowEvent = $queryData->selek1("tbl_content","idx='".$numEvent[$i]."'");
				if ($rowEvent->idx!="") {
					$tipe = explode("-",$rowEvent->tipe);
					$mytanggal = explode("[break]",$rowEvent->header_c);
					$lasttipe[] = $tipe[1];
					$j = ($g-1);
					if ($c==0)
						$valX = $queryData->selek1("ikadir_kat","id_dirkat='".$tipe[1]."'")->dir_kat;
			
					if ($tipe[1]!=$lasttipe[$j]) {
						$c = 0;
						$valX = $queryData->selek1("ikadir_kat","id_dirkat='".$tipe[1]."'")->dir_kat;
						$lasttipe[$g] = $tipe[1];
						if (($c==0) && ($valX))
							echo '<div><h4>'.$valX.'</h4></div>';
						$g++;
					} elseif (($c==0) && ($valX)) {
						echo '<div><h4>'.$valX.'</h4></div>';
					}
					echo '<h2><a title="'.strip_tags($rowEvent->judul).'" href="'.URL_PATH.'index.php/1/detail/'.$rowEvent->idx."/".$queryData->permalink($rowEvent->idx).'/">'.strip_tags($rowEvent->judul).'</a></h2>';
					echo '<div class="event-date-begin">'.$EVENT_DATE_BEGIN.': '.$queryData->tanggalan($mytanggal[0],false,false,true).'</div>';
					echo '<div class="event-date-end">'.$EVENT_DATE_END.': '.$queryData->tanggalan($mytanggal[1],false,false,true).'</div>';
					echo '<div class="more">[ <a href="'.URL_PATH.'index.php/1/detail/'.$rowEvent->idx.'/'.$queryData->permalink($rowEvent->idx).'/" title="'.$rowEvent->judul.'">'.$DEV_MORE.'...</a> ] </div>';
					$c++;
				}
			}
		}

		echo '</div>';
		
		if ($params['pagination']) {
			echo '<div align="center" style="font-size:11px">'.$divpage.'</div><br />';
		}
	} else {
		$numrec = NUMREC;
		
		$arr1 = array("<fieldset","<input","</fieldset","<text","</text","<legend","</legend","<label","</label","<form","</form","<script","<?php","<%","<!--","<link","<style","</scr","</link","</code","<pre","/pre>");
		$arr2 = array("&lt;fieldset","&lt;input","&lt;/fieldset","&lt;text","&lt;/text","&lt;legend","&lt;/legend","&lt;label","&lt;/label","&lt;form","&lt;/form","&lt;script","&lt;?php","&lt;%","&lt;!--","&lt;link","&lt;a","&lt;/scr","&lt;link","&lt;code","<div align=\"center\"><pre style=\"position:relative; width:450px; overflow:auto; text-align:left;\"","/pre></div>");
		$sqlEventdet = "SELECT * FROM tbl_content WHERE idx='".$kode."' AND status='1' LIMIT 1";
		$qryEventdet = mysql_query($sqlEventdet);
		$rowEventdet = mysql_fetch_object($qryEventdet);
		$tipe = explode("-",$rowEventdet->tipe);
		$mytanggal = explode("[break]",$roeEventdet->header_c);
		$arrtipe = "tipe LIKE '".$tipe[0]."%'";
		echo '<div class="main-content">';
        echo '<h2 title="'.strip_tags($rowEventdet->judul).'">'.$rowEventdet->judul.'</h2>&nbsp;';
		echo '<div class="author">'.$DEV_SENT_BY.' '.$queryData->cekUser($rowEventdet->author).' '.$DEV_SENT_ON.' '.$queryData->tanggalan($rowEventdet->tanggal).'</div>';
		echo '<div class="event-date-begin">'.$queryData->tanggalan($mytanggal[0],false,false,true).'</div>';
		echo '<div class="event-date-end">'.$queryData->tanggalan($mytanggal[1],false,false,true).'</div>';
		echo str_replace($arr1,$arr2,$rowEventdet->isi)."";
		echo '</div>';
		if (defined('USE_TRACKBACK')) {
			echo '<div id="trackback">Trackback URl : <a href="http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'">'.$rowEventdet->judul.'</a></div>';	
			echo '<div id="rsssyndicate">RSS : <a href="http://'.$_SERVER['HTTP_HOST'].'/rss.php?id='.$rowEventdet->idx.'">'.$rowEventdet->judul.'</a></div><br />';
		}
		if (defined('USE_TWITTER')) {
			echo '<div id="usetwitter"><a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="'.USE_TWITTER_ID.'">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>';
		}
		if (defined('USE_FACEBOOK')) {
			echo '<div id="facebooklike"><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="'.urlencode("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']).'" font="tahoma"></fb:like></div>';	
		}
		if (defined('USE_ADDTHIS')) {
			echo '<div id="addthis">';
			echo '<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_favorites"></a>
<a class="addthis_button_email"></a>
<a class="addthis_button_print"></a>
<span class="addthis_separator">|</span>
<a href="http://www.addthis.com/bookmark.php?v=250&amp;username='.USE_ADDTHIS_ID.'" class="addthis_button_compact"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username='.USE_ADDTHIS_ID.'"></script>
<!-- AddThis Button END --></div>';	
		}
		
		$sqlfil[] = "AND idx<>'".$rowEventdet->idx."' ";
		$vv = "";
		foreach ($sqlfil as $val) {
			$vv .= $val;
		}
		(is_numeric($res[1])) ? $page = strip_tags($res[1]) : $page = 1;
		($_GET['showview']) ? $showview = strip_tags($_GET['showview']) : $showview = 'detail/'.$kode;
		$numrec = NUMREC;
		$perpage = 5;	//jumlah record yang ditampilkan perhalaman
		$defshow = DEFSHOW;
		if ($page!=0)
			$piro=($page-1)*$perpage;
		else
			$piro = 0;

		$sqlContent = "SELECT * FROM tbl_content WHERE ".$arrtipe." AND status='1' ".$vv." ORDER BY tanggal DESC";
		$qryContent = mysql_query($sqlContent);
		$numb1 = mysql_num_rows($qryContent);
		//echo $sqlContent;
		if ($numb1!=0) {
			echo '<br /><h2>'.$NEWS_RELATED.'</h2><hr class="lines" />';
		}
	
		while ($rowContent = mysql_fetch_object($qryContent)) {
			$numEvent[$numrec] = $rowContent->idx;
			$numrec++;
		}
		
		$divpage = $queryData->showpage('index.php',$numrec,$defshow,$perpage,$page,$showview);
	
		for ($i=$piro;$i<($piro+$perpage);$i++) {
			$rowContent = $queryData->selek1("tbl_content","idx='".$numEvent[$i]."'");
			if ($rowContent->idx!="") {
				echo "<a class=\"title\" href=\"".URL_PATH."index.php/1/detail/".$rowContent->idx."/".$queryData->permalink($rowContent->idx)."/\" title=\"".$rowContent->judul."\">".$rowContent->judul."</a><br/ ><br />";	
			}
		}
		if ($numb1!=0) {
			echo '<div align="center" style="font-size:11px">'.$divpage.'</div>';
		}
	} 
	echo '<br />';
?>